package com.tpay.server.guice;

import com.google.inject.persist.PersistFilter;
import com.google.inject.persist.jpa.JpaPersistModule;
import com.google.inject.servlet.ServletModule;
import com.gwtplatform.dispatch.server.guice.DispatchServiceImpl;
import com.gwtplatform.dispatch.shared.ActionImpl;
import com.gwtplatform.dispatch.shared.SecurityCookie;
import com.tpay.server.GeneralDao;
import com.tpay.server.GeneralDaoImpl;
import com.tpay.shared.SharedTokens;

public class PayServletModule extends ServletModule {
	public static final String DEFAULT_SERVICE_PATH = "/";
	public static final String REPORTS_SERVICE_PATH = "/reports/*";
	public static final String FILE_UPLOAD_SERVICE_PATH = "/upload/*";
	public static final String FILE_DOWNLOAD_SERVICE_PATH = "/download/*";

	@Override
	protected void configureServlets() {
		// Protect against XSRF attacks - securityCookieName = "JSESSIONID";
		bindConstant().annotatedWith(SecurityCookie.class).to(SharedTokens.securityCookieName);
		
	    install(new JpaPersistModule(this.getServletContext().getInitParameter("PU-NAME")));	// PU-NAME은 web.xml에 정의되어 있음
	    filter("/").through(PersistFilter.class);
	    this.bind(GeneralDao.class).to(GeneralDaoImpl.class);
	    
		// For GWT 2.1.1
		serve(DEFAULT_SERVICE_PATH + ActionImpl.DEFAULT_SERVICE_NAME).with(DispatchServiceImpl.class);
	}
}
